<?php
/**
 * Created by PhpStorm.
 * User: Alex
 * DateTime: 18-9-7上午11:55
 */

namespace ThirdPartyAuthorizeBundle\thirdPartyAuthorize\common;


use ThirdPartyAuthorizeBundle\thirdPartyAuthorize\entity\WeCharUserInfo;

class WeCharUserInfoTool
{
    /**
     * @var null|WeCharUserInfo
     */
    private $weCharUserInfo = null;

    function __construct()
    {
        if($this->weCharUserInfo ==  null){
            $this->weCharUserInfo = new WeCharUserInfo();
        }
    }

   public function weCharInfoArr2weCharUserInfoObj($weCharInfoArr)
   {
       $openid = null;
       $nickname = null;
       $sex = null;
       $language = null;
       $city = null;

       $province = null;
       $country = null;
       $headimgurl = '';
       $privilege = null;
       $unionid = null;

       if(array_key_exists('openid',$weCharInfoArr)){
           $openid = $weCharInfoArr['openid'];
       }

       if(array_key_exists('nickname',$weCharInfoArr)){
           $nickname = $weCharInfoArr['nickname'];
       }

       if(array_key_exists('sex',$weCharInfoArr)){
           $sex = $weCharInfoArr['sex'];
       }


       if(array_key_exists('language',$weCharInfoArr)){
           $language = $weCharInfoArr['language'];
       }

       if(array_key_exists('city',$weCharInfoArr)){
           $city = $weCharInfoArr['city'];
       }

       if(array_key_exists('province',$weCharInfoArr)){
           $province = $weCharInfoArr['province'];
       }

       if(array_key_exists('country',$weCharInfoArr)){
           $country = $weCharInfoArr['country'];
       }

       if(array_key_exists('headimgurl',$weCharInfoArr)){
           $headimgurl = StringTool::encodeContentWithEmoticon($weCharInfoArr['headimgurl'], false);
       }

       if(array_key_exists('privilege',$weCharInfoArr)){
           $privilege = $weCharInfoArr['privilege'];
       }

       if(array_key_exists('unionid',$weCharInfoArr)){
           $unionid = $weCharInfoArr['unionid'];
       }

       $this->weCharUserInfo->setOpenid($openid);
       $this->weCharUserInfo->setNickname($nickname);
       $this->weCharUserInfo->setSex($sex);
       $this->weCharUserInfo->setLanguage($language);
       $this->weCharUserInfo->setCity($city);

       $this->weCharUserInfo->setProvince($province);
       $this->weCharUserInfo->setCountry($country);
       $this->weCharUserInfo->setHeadimgurl($headimgurl);
       $this->weCharUserInfo->setPrivilege($privilege);
       $this->weCharUserInfo->setUnionid($unionid);

       return $this->weCharUserInfo;
   }
}